function HandlePageBackendPayee(gui, operater, now, options) {
  this._gui = gui;
  this._operator = operater;
  this._now = now;
  this._options = options;
    
  this._createElements();
};

HandlePageBackendPayee.prototype._createElements = function() {
  this._loadData();
};

HandlePageBackendPayee.prototype._loadData = function() {
  this._payee = null;
  this._retrievePayee();
};

HandlePageBackendPayee.prototype._verifyData = function() {
  if (this._payee) {
    this._oldPayee = MiscUtils.clone(this._payee);
    this._updateElements();
  }
};

HandlePageBackendPayee.prototype._retrievePayee = function() {
  var _self = this;
  if (this._options.id) {
    new RequestUtils()._read('pz_payee', null, 'd.oid = ' + this._options.id, null, null, null, null, function(result, params) { _self._payee = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                                 _self._verifyData.call(_self);
                                                                                                                               }, null);
  } else {
    this._payee = pz_payee.instance();
    this._verifyData();
  }
};

HandlePageBackendPayee.prototype._updateElements = function() {
  var _self = this;

  this._gui.payee.value = this._payee.name;
  this._gui.payee.onchange = function() { _self._payee.name = this.value; };
  
  this._gui.save.onclick = function() { if (_self._payee.name == '') { 
                                          window.alert('名称不能为空');
                                          return;
                                        }
                                        if (_self._options.id) {
                                          if (_self._oldPayee.name != _self._payee.name) {
                                            _self._loadDatas();
                                          } else {
                                            history.back();
                                          }
                                        } else {
                                          new RequestUtils()._write('pz_payee', [_self._payee], [], function() { history.back(); }, {pos: DOMUtils.findPos(this)}); };
                                        }
  this._gui.cancel.onclick = function() { history.back(); };
};


HandlePageBackendPayee.prototype._loadDatas = function() {
  var _self = this;
  this._expenses = null;
  
  var r = window.confirm("IT WILL TAKE SOME TIME TO AFFECT ALL EXPENSES, CONTINUE?");
  if (r) {
    this._retrieveExpenses();
  }
};

HandlePageBackendPayee.prototype._verifyExpenseData = function() {
  if (this._expenses) {
    this._updateExpenses();
  }
};

HandlePageBackendPayee.prototype._retrieveExpenses = function() {
  var _self = this;
  new RequestUtils()._read('pz_expense', null, 'd.payee = \'' + this._oldPayee.name + '\'', null, null, null, null, function(result, params) { _self._expenses = result.data;
                                                                                                                                               _self._verifyExpenseData.call(_self);
                                                                                                                                             }, {pos: DOMUtils.findPos(this._gui.save)});
};

HandlePageBackendPayee.prototype._updateExpenses = function() {
  var _self = this;
  var expenses = [];
  for (var i = 0, il = this._expenses.length; i < il; i++) {
    var exp = this._expenses[i];
    exp.payee = this._payee.name;
    expenses[expenses.length] = exp;
  }
  new RequestUtils()._write2([{n: 'pz_expense', a: expenses, r: []}, {n: 'pz_payee', a: [this._payee], r: []}], function() { history.back(); }, {pos: DOMUtils.findPos(this._gui.save)});
};

